package cn.takovh.zpl.bean;

import org.dom4j.Element;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Seq implements ElementBean {
    private List<Media> mediaList;

    public Seq() {
    }

    public Seq(List<Media> mediaList) {
        this.mediaList = mediaList;
    }

    public List<Media> getMediaList() {
        return mediaList;
    }

    public void setMediaList(List<Media> mediaList) {
        this.mediaList = mediaList;
    }

    @Override
    public void getElement(Element root) {
        for (Media media : mediaList) {
            Element child = root.addElement("media");
            media.getElement(child);
        }
    }

    @Override
    public void parseElement(Element root) {
        this.mediaList = new ArrayList<>();
        for (Iterator<Element> it = root.elementIterator(); it.hasNext(); ) {
            Element element = it.next();
            String name = element.getName();
            switch (name) {
                case "media":
                    Media media = new Media();
                    media.parseElement(element);
                    this.mediaList.add(media);
                    break;
                default:
                    throw new IllegalArgumentException(name);
            }
        }
    }
}
